/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */
package br.ufmg.dees.insane.ui.rich.learn.learn_view;

import java.awt.BorderLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;

import br.ufmg.dees.insane.model.disc.fem.FemModel;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.GridController;
import br.ufmg.dees.insane.ui.rich.learn.learn_controller.LearnController;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.AboutCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.BugReportCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.CloseCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.Command;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.DeleteCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.DoesNothingCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.ExitCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.ExportJPEGCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.ExportPDFCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.ExportPSCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.ExportXMLCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.FitCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.GeneralSettingsCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.GridCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.GridSettingsCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.HelpTopicsCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.ImportXMLCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.LastZoomCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.LimitsSettingsCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.OpenCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.PrintCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.RedoCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.RedrawCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.SaveFileAsCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.SaveFileCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.ScalesSettingsCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.SelectAllCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.SettingsCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.SnapCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.UndoCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.ZoomAllCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.ZoomCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.ZoomInCommand;
import br.ufmg.dees.insane.ui.rich.learn.learn_view.command.ZoomOutCommand;

/**
*
* @author Moreira, Renata & Pitangueira, Roque
* @since May 2005
*/

public class LearnView extends IView {
	
	protected LearnInterface parent;
	protected FemModel model;
	
//	Commands
    private Command openCmd;
    private Command saveFileCmd;
    private Command saveFileAsCmd;
    private Command printCmd;
    private Command exportJPEGCmd;
    private Command exportPSCmd;
	private Command exportXMLCmd;
	private Command exportPDFCmd;
	private Command importCmd;
    private Command closeCmd;
    private Command exitCmd;
    private Command settingsCmd;
    
	private Command genSettingsCmd;
	private Command limSettingsCmd;
	private Command gridSettingsCmd;
	private Command scaSettingsCmd;

	private Command gridCmd;
    private Command snapCmd;
  
    private Command selectAllCmd;
    private Command deleteCmd;
    private Command zoomCmd;
    private Command zoomInCmd;
    private Command zoomOutCmd;
    private Command fitCmd;
    private Command zoomAllCmd;
    private Command lastZoomCmd;
    private Command redrawCmd;
    
	private UndoCommand undoCmd;
    private RedoCommand redoCmd;
	
	private Command helpTopicsCmd;
    private Command bugReportCmd;
	private Command aboutCmd;
	

	 protected JMenu menuFile = new JMenu("File");
	    protected CmdMenu itemNew = new CmdMenu("New", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/New16.gif")));
	    protected CmdMenu itemOpen = new CmdMenu("Open", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Open16.gif")));
	    protected CmdMenu itemSave = new CmdMenu("Save", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Save16.gif")));
	    protected CmdMenu itemSaveAs = new CmdMenu("Save As", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/SaveAs16.gif")));
	    protected CmdMenu itemPrint = new CmdMenu("Print", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Print16.gif")));
	    protected JMenu menuExport = new JMenu("Export");
	    protected CmdMenu itemJPEG = new CmdMenu("JPEG Image", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Export16.gif")));
	    protected CmdMenu itemPS = new CmdMenu("PostScript", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Export16.gif")));
		protected CmdMenu itemXML = new CmdMenu("XML File", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Export16.gif")));
		protected CmdMenu itemPDF = new CmdMenu("PDF File", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Export16.gif")));
		protected JMenu menuImport = new JMenu("Import");
		protected CmdMenu itemImport = new CmdMenu("XML File", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Import16.gif")));
	    protected CmdMenu itemClose = new CmdMenu("Close");
	    protected CmdMenu itemExit = new CmdMenu("Exit");
	    
	    protected JMenu menuEdit = new JMenu("Edit");
	    protected CmdMenu itemUndo = new CmdMenu("Undo", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Undo16.gif")));
	    protected CmdMenu itemRedo = new CmdMenu("Redo", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Redo16.gif")));
	    protected CmdMenu itemCut = new CmdMenu("Cut", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Cut16.gif")));
	    protected CmdMenu itemCopy = new CmdMenu("Copy", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Copy16.gif")));
	    protected CmdMenu itemPaste = new CmdMenu("Paste", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Paste16.gif")));
	    protected CmdMenu itemSelectAll = new CmdMenu("Select All");
	    protected CmdMenu itemDelete = new CmdMenu("Delete", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Delete16.gif")));
	    
	    protected JMenu menuView = new JMenu("View");
	    protected JMenu menuZoom = new JMenu("Zoom");
	    protected CmdMenu itemWindow = new CmdMenu("Window", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Zoom16.gif")));
	    protected CmdMenu itemZoomIn = new CmdMenu("In", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomIn16.gif")));
	    protected CmdMenu itemZoomOut = new CmdMenu("Out", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomOut16.gif")));
	    protected CmdMenu itemExtents = new CmdMenu("Extents", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomExtents16.gif")));
	    protected CmdMenu itemAll = new CmdMenu("All", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomAll16.gif")));
	    protected CmdMenu itemLastZoom = new CmdMenu("Last", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomPrevious16.gif")));
		protected CmdMenu itemRedraw = new CmdMenu("Redraw", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Redraw16.gif")));
	
		
	    protected JMenu menuSettings = new JMenu("Settings");
	    protected CmdMenu itemSettings = new CmdMenu("Settings", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Settings16.gif")));
		protected CmdMenu itemGenSettings = new CmdMenu("General Settings");
		protected CmdMenu itemLimSettings = new CmdMenu("Limits Settings");
		protected CmdMenu itemGridSettings = new CmdMenu("Grid Settings");
		protected CmdMenu itemScaSettings = new CmdMenu("Scales Settings");
		
		
		 //Menu do Processador Interativo
	    protected JMenu menuProcInteractive = new JMenu("Interactive");
	    
	    protected JMenu menuHelp = new JMenu("Help");
	    protected CmdMenu itemHelpTopics = new CmdMenu("Help Topics", new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Help16.gif")));
	    protected CmdMenu itemBugReport = new CmdMenu("Bug Report",  new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Bug16.gif")));
		protected CmdMenu itemAbout = new CmdMenu("About",  new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/About16.gif")));
		
		protected JToolBar fileToolBar = new JToolBar();
		protected CmdButton open = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Open16.gif")));
		protected CmdButton save = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Save16.gif")));
		protected CmdButton saveAs = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/SaveAs16.gif")));
		protected CmdButton print = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Print16.gif")));
		    
		protected JToolBar zoomToolBar = new JToolBar();
		protected CmdButton redraw = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Redraw16.gif")));
		protected CmdButton fit = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomExtents16.gif")));
		protected CmdButton zoom = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Zoom16.gif")));
		protected CmdButton zoomIn = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomIn16.gif")));
		protected CmdButton zoomOut = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomOut16.gif")));
		protected CmdButton zoomAll = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomAll16.gif")));
		protected CmdButton zoomPrevious = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/ZoomPrevious16.gif")));
		    
		protected JToolBar editToolBar = new JToolBar();
		protected CmdButton undo = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Undo16.gif")));
		protected CmdButton redo = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Redo16.gif")));
		protected CmdButton cut = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Cut16.gif")));
		protected CmdButton copy = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Copy16.gif")));
		protected CmdButton paste = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Paste16.gif")));
		protected CmdButton delete = new CmdButton(new ImageIcon(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Delete16.gif")));
		
		//Tool Bar do processador Interativo
		protected JToolBar interactiveProcToolBar = new JToolBar();
		
		protected CmdToggleButton grid = new CmdToggleButton("Grid");
		protected CmdToggleButton snap = new CmdToggleButton("Snap");
        
		public LearnView(LearnInterface parent){}
		    
		public LearnView(){}
	
		public LearnView(LearnInterface parent, FemModel m){
		this.parent = parent;
		this.initCommands();
		super.setViewState(new LearnViewState());
		super.setDrawingArea(new DrawingArea((IView)this));
		super.setController(new LearnController(m, this));

        String gAnlType = m.getGlobalAnalysisModel().getType();
		
		if (!(gAnlType.equals("Grid"))) {
		    super.setController(new LearnController(this));
		} else {
		    super.setController(new GridController(this));
		}
		
		menuFile.setMnemonic(KeyEvent.VK_F);
	    
	    menuFile.add(itemNew);
	    itemNew.addActionListener(parent);
	    itemNew.setMnemonic(KeyEvent.VK_N);
	    itemNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
	    
	    menuFile.add(itemOpen);
	    itemOpen.setCommand(openCmd);
	    itemOpen.addActionListener(parent);
	    itemOpen.setMnemonic(KeyEvent.VK_O);
	    itemOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
	    
	    menuFile.add(itemSave);
	    itemSave.setCommand(saveFileCmd);
	    itemSave.setEnabled(false);
	    itemSave.addActionListener(parent);
	    itemSave.setMnemonic(KeyEvent.VK_S);
	    itemSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
	    
	    menuFile.add(itemSaveAs);
	    itemSaveAs.setCommand(saveFileAsCmd);
	    itemSaveAs.setEnabled(false);
	    itemSaveAs.addActionListener(parent);
		itemSaveAs.setMnemonic(KeyEvent.VK_A);
	    itemSaveAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.SHIFT_MASK));
	    
	    menuFile.add(itemClose);
	    itemClose.setCommand(closeCmd);
	    itemClose.setEnabled(false);
	    itemClose.addActionListener(parent);
	    itemClose.setMnemonic(KeyEvent.VK_C);
	    itemClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK));
	    
	    menuFile.addSeparator();
	    
	    menuFile.add(itemPrint);
	    itemPrint.setCommand(printCmd);
	    itemPrint.setEnabled(false);
	    itemPrint.addActionListener(parent);
	    itemPrint.setMnemonic(KeyEvent.VK_P);
	    itemPrint.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK));
	    
		menuFile.add(menuImport);
		menuImport.setMnemonic(KeyEvent.VK_I);
		
		menuImport.add(itemImport);
	    itemImport.setCommand(importCmd);
	    itemImport.setEnabled(true);
		itemImport.setMnemonic(KeyEvent.VK_X);
		itemImport.addActionListener(parent);
	    
		menuFile.add(menuExport);
	    menuExport.setEnabled(false);
		menuExport.setMnemonic(KeyEvent.VK_E);
	    
		menuExport.add(itemJPEG);
		itemJPEG.setCommand(exportJPEGCmd);
		itemJPEG.setMnemonic(KeyEvent.VK_J);
	    itemJPEG.addActionListener(parent);
	    
	    menuExport.add(itemPDF);
	    itemPDF.setCommand(exportPDFCmd);
		itemPDF.setMnemonic(KeyEvent.VK_P);
	    itemPDF.addActionListener(parent);
		
		menuExport.add(itemPS);
	    itemPS.setCommand(exportPSCmd);
		itemPS.setMnemonic(KeyEvent.VK_S);
	    itemPS.addActionListener(parent);
	    
		menuExport.add(itemXML);
	    itemXML.setCommand(exportXMLCmd);
		itemXML.setMnemonic(KeyEvent.VK_X);
	    itemXML.addActionListener(parent);
		
		menuFile.addSeparator();
	    
	    menuFile.add(itemExit);
	    itemExit.setMnemonic(KeyEvent.VK_X);
	    itemPrint.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
		itemExit.setCommand(exitCmd);
	    itemExit.addActionListener(parent);
	    
	    //Setting menu edit
	    menuEdit.setMnemonic(KeyEvent.VK_E);
	    
	    menuEdit.add(itemUndo);
	    itemUndo.setEnabled(false);
	    itemUndo.setCommand(undoCmd);
	    itemUndo.addActionListener(parent);
	    itemUndo.setMnemonic(KeyEvent.VK_U);
	    itemUndo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.CTRL_MASK));
	    
	    menuEdit.add(itemRedo);
	    itemRedo.setEnabled(false);
	    itemRedo.setCommand(redoCmd);
	    itemRedo.addActionListener(parent);
	    itemRedo.setMnemonic(KeyEvent.VK_R);
	    itemRedo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, ActionEvent.CTRL_MASK));
	    
	    menuEdit.addSeparator();
	    
	    menuEdit.add(itemCut);
	    itemCut.setEnabled(false);
	    itemCut.addActionListener(parent);
	    itemCut.setMnemonic(KeyEvent.VK_C);
	    itemCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
	    
	    menuEdit.add(itemCopy);
	    itemCopy.setEnabled(false);
	    itemDelete.addActionListener(parent);
	    itemCopy.setMnemonic(KeyEvent.VK_O);
	    itemCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
	    
	    menuEdit.add(itemPaste);
	    itemPaste.setEnabled(false);
	    itemPaste.addActionListener(parent);
	    itemPaste.setMnemonic(KeyEvent.VK_P);
	    itemPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
	    
	    menuEdit.addSeparator();
	    
	    menuEdit.add(itemSelectAll);
	    itemSelectAll.setCommand(selectAllCmd);
	    itemSelectAll.addActionListener(parent);
	    itemSelectAll.setMnemonic(KeyEvent.VK_A);
	    itemSelectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
	    
	    menuEdit.add(itemDelete);
	    itemDelete.setCommand(deleteCmd);
	    itemDelete.addActionListener(parent);
	    itemDelete.setMnemonic(KeyEvent.VK_D);
	    itemDelete.setAccelerator(KeyStroke.getKeyStroke("DELETE"));
	    
	    //Setting menu view
	    menuView.setMnemonic(KeyEvent.VK_V);
	    
	    menuZoom.add(itemWindow);
	    itemWindow.setCommand(zoomCmd);
	    itemWindow.addActionListener(parent);
	    itemWindow.setMnemonic(KeyEvent.VK_W);
	    itemWindow.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, ActionEvent.SHIFT_MASK));
	    
	    menuZoom.add(itemZoomIn);
	    itemZoomIn.setCommand(zoomInCmd);
	    itemZoomIn.addActionListener(parent);
	    itemZoomIn.setMnemonic(KeyEvent.VK_I);
	    itemZoomIn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, ActionEvent.SHIFT_MASK));
		
	    menuZoom.add(itemZoomOut);
	    itemZoomOut.setCommand(zoomOutCmd);
	    itemZoomOut.addActionListener(parent);
	    itemZoomOut.setMnemonic(KeyEvent.VK_O);
		itemZoomOut.setAccelerator(KeyStroke.getKeyStroke("MINUS"));
	    
	    menuZoom.add(itemAll);
	    itemAll.setCommand(zoomAllCmd);
	    itemAll.addActionListener(parent);
	    itemAll.setMnemonic(KeyEvent.VK_A);
	    itemAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.SHIFT_MASK));
		
		menuZoom.add(itemExtents);
	    itemExtents.setCommand(fitCmd);
	    itemExtents.addActionListener(parent);
	    itemExtents.setMnemonic(KeyEvent.VK_E);
	    itemExtents.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.SHIFT_MASK));
	    
	    menuZoom.add(itemLastZoom);
	    itemLastZoom.setCommand(lastZoomCmd);
	    itemLastZoom.addActionListener(parent);
	    itemLastZoom.setMnemonic(KeyEvent.VK_L);
	    itemLastZoom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.SHIFT_MASK));
		
		menuView.add(menuZoom);
	    menuZoom.setMnemonic(KeyEvent.VK_Z);
		
		menuView.addSeparator();
		
		menuView.add(itemRedraw);
	    itemRedraw.setMnemonic(KeyEvent.VK_R);
		itemRedraw.setCommand(redrawCmd);
		itemLastZoom.addActionListener(parent);
		
		menuView.addSeparator();
		

		
		//Setting menu settings
	    menuSettings.setMnemonic(KeyEvent.VK_S);
		
		menuSettings.add(itemSettings);
		itemSettings.setCommand(settingsCmd);
		itemSettings.setMnemonic(KeyEvent.VK_S);
	    itemSettings.addActionListener(parent);
		
		menuSettings.addSeparator();
		
		menuSettings.add(itemGenSettings);
		itemGenSettings.setCommand(genSettingsCmd);
		itemGenSettings.setMnemonic(KeyEvent.VK_G);
	    itemGenSettings.addActionListener(parent);
		
		menuSettings.add(itemLimSettings);
		itemLimSettings.setCommand(limSettingsCmd);
		itemLimSettings.setMnemonic(KeyEvent.VK_L);
	    itemLimSettings.addActionListener(parent);
		
		menuSettings.add(itemGridSettings);
		itemGridSettings.setCommand(gridSettingsCmd);
		itemGridSettings.setMnemonic(KeyEvent.VK_G);
	    itemGridSettings.addActionListener(parent);
		
		menuSettings.add(itemScaSettings);
		itemScaSettings.setCommand(scaSettingsCmd);
		itemScaSettings.setMnemonic(KeyEvent.VK_C);
	    itemScaSettings.addActionListener(parent);
	    
	    //Setting menu help
	    menuHelp.setMnemonic(KeyEvent.VK_H);
		
	    menuHelp.add(itemHelpTopics);
		itemHelpTopics.setCommand(helpTopicsCmd);
	    itemHelpTopics.addActionListener(parent);
	    itemHelpTopics.setMnemonic(KeyEvent.VK_H);
	    itemHelpTopics.setAccelerator(KeyStroke.getKeyStroke("F1"));
		
	    menuHelp.addSeparator();
	    
	    menuHelp.add(itemBugReport);
	    itemBugReport.setCommand(bugReportCmd);
		itemBugReport.setMnemonic(KeyEvent.VK_B);
	    itemBugReport.addActionListener(parent);
		
		menuHelp.add(itemAbout);
	    itemAbout.setCommand(aboutCmd);
		itemAbout.setMnemonic(KeyEvent.VK_A);
	    itemAbout.addActionListener(parent);
	    
	    fileToolBar.add(open);
        open.setToolTipText("Open Model");
        open.setCommand(openCmd);
        open.addActionListener(parent);
        
        fileToolBar.add(save);
        save.setToolTipText("Save Model");
        save.setCommand(saveFileCmd);
        save.addActionListener(parent);
        
        fileToolBar.add(saveAs);
        saveAs.setToolTipText("Save Model As");
        saveAs.setCommand(saveFileAsCmd);
        saveAs.addActionListener(parent);
        
        fileToolBar.add(print);
        print.setToolTipText("Print the canvas");
        print.setCommand(printCmd);
        print.addActionListener(parent);
        
        //Setting zoom tool bar
        
        zoomToolBar.add(zoom);
        zoom.setToolTipText("Zoom Window");
        zoom.setCommand(zoomCmd);
        zoom.addActionListener(parent);
        
        zoomToolBar.add(zoomIn);
        zoomIn.setToolTipText("Zoom In");
        zoomIn.setCommand(zoomInCmd);
        zoomIn.addActionListener(parent);
        
        zoomToolBar.add(zoomOut);
        zoomOut.setToolTipText("Zoom Out");
        zoomOut.setCommand(zoomOutCmd);
        zoomOut.addActionListener(parent);
        
        zoomToolBar.add(zoomAll);
        zoomAll.setToolTipText("Zoom All");
        zoomAll.setCommand(zoomAllCmd);
        zoomAll.addActionListener(parent);
        
        zoomToolBar.add(fit);
        fit.setToolTipText("Zoom Extents");
        fit.setCommand(fitCmd);
        fit.addActionListener(parent);
        
		zoomToolBar.add(zoomPrevious);
        zoomPrevious.setToolTipText("Zoom Last");
        zoomPrevious.setCommand(lastZoomCmd);
        zoomPrevious.addActionListener(parent);
		
        zoomToolBar.add(redraw);
        redraw.setToolTipText("Redraw All");
        redraw.setCommand(redrawCmd);
        redraw.addActionListener(parent);
        
        //Setting edit tool bar
        
        editToolBar.add(undo);
        undo.setToolTipText("Undo");
        undo.setEnabled(false);
        undo.setCommand(undoCmd);
        undo.addActionListener(parent);
        
        editToolBar.add(redo);
        redo.setToolTipText("Redo");
        redo.setEnabled(false);
        redo.setCommand(redoCmd);
        redo.addActionListener(parent);
        
        editToolBar.add(cut);
        cut.setEnabled(false);
        cut.setToolTipText("Cut");
        cut.addActionListener(parent);
        
        editToolBar.add(copy);
        copy.setEnabled(false);
        copy.setToolTipText("Copy");
        copy.addActionListener(parent);
        
        editToolBar.add(paste);
        paste.setEnabled(false);
        paste.setToolTipText("Paste");
        paste.addActionListener(parent);
        
        editToolBar.add(delete);
        delete.setToolTipText("Delete");
        delete.setCommand(deleteCmd);
        delete.addActionListener(parent);
        
	}

	public void init(){
		
	    parent.getMenuPanel().removeAll();
	    parent.getMenuPanel().add(menuFile);
		itemSave.setEnabled(false);
		itemSaveAs.setEnabled(false);
		itemClose.setEnabled(false);
		itemPrint.setEnabled(false);
		menuExport.setEnabled(false);
		
		parent.getMenuPanel().add(menuHelp);
		itemHelpTopics.setEnabled(true);
		itemAbout.setEnabled(true);
		
		grid.setEnabled(true);
		snap.setEnabled(true);
		
		parent.getToolPanel().removeAll();
		parent.getToolPanel().add(fileToolBar);
		save.setEnabled(false);
		saveAs.setEnabled(false);
		print.setEnabled(false);
		
		parent.getTree().expandRow(0);
		parent.getTree().expandRow(1);
		parent.getTree().expandRow(2);
		parent.getTree().expandRow(5);
		parent.getTree().expandRow(8);
		parent.getTree().expandRow(14);
		parent.getTree().expandRow(17);
		parent.getTree().setEnabled(true);
		
		
		parent.getSplitPane().setDividerLocation(200);
		this.getController().compose();
		parent.getDrawPanel().removeAll();
		parent.getDrawPanel().add(this.getDrawingArea(), BorderLayout.CENTER);
		this.getDrawingArea().removeAllCommands();
		this.getDrawingArea().setClickedCommand(new DoesNothingCommand(parent));
		this.getDrawingArea().setCursor();
		parent.getDrawPanel().repaint();
		parent.getDrawPanel().updateUI();

		setMessage("Escola de Engenharia da UFMG");
		
		parent.getConsolePanel().setVisible(false);
		
		parent.setCoord("" + 6.0, "" + 0.0);
		
		parent.getStatePanel().removeAll();
		grid.setMargin(new Insets(0,1,0,1));
        grid.setCommand(gridCmd);
        grid.addActionListener(parent);
        parent.getStatePanel().add(grid);
        
        snap.setMargin(new Insets(0,1,0,1));
        snap.setCommand(snapCmd);
        snap.addActionListener(parent);
        parent.getStatePanel().add(snap);
		
		parent.repaint();		    
}
	
	
	/** Adds a Command to the undoList.*/
    public void addToUndo(Command cmd) {
        undoCmd.add(cmd);
        itemUndo.setEnabled(true);
        undo.setEnabled(true);
    }
    
//*****************************************************************************
	
	/** Adds a Command to the redoList.*/
    public void addToRedo(Command cmd) {
        if (!(cmd instanceof DeleteCommand)){
            redoCmd.add(cmd);
            itemRedo.setEnabled(true);
            redo.setEnabled(true);
        }
    }
	
//*****************************************************************************
	
	/** Disables the redo command.*/
    public void nothingToRedo() {
        redoCmd.clear();
        itemRedo.setEnabled(false);
        redo.setEnabled(false);
    }
	
//*****************************************************************************
	
	/** Disables the undo command.*/
    public void nothingToUndo() {
        undoCmd.clear();
        itemUndo.setEnabled(false);
        undo.setEnabled(false);
	}

    
    /** Returns the UndoCommand of this Interface.
	*@return The UndoCommand of this Interface.
	*/
	public UndoCommand getUndoCommand() {
		return undoCmd;
	}
	
//*****************************************************************************
	
	/** Returns the RedoCommand of this Interface.
	*@return The RedoCommand of this Interface.
	*/
	public RedoCommand getRedoCommand() {
		return redoCmd;
	}
   
    
//	*****************************************************************************
	
	/** Cleans the results stored at Model.
	*/
	public void cleanResults() {
		((LearnController)this.getController()).getModel().cleanResults();
	}

    private void initCommands(){
        openCmd = new OpenCommand(parent);
        saveFileCmd = new SaveFileCommand(parent);
        saveFileAsCmd = new SaveFileAsCommand(parent);
         printCmd = new PrintCommand(parent);
         exportJPEGCmd = new ExportJPEGCommand(parent);
         exportPSCmd = new ExportPSCommand(parent);
    	 exportXMLCmd = new ExportXMLCommand(parent);
    	 exportPDFCmd = new ExportPDFCommand(parent);
    	 importCmd = new ImportXMLCommand(parent);
         closeCmd = new CloseCommand(parent);
         exitCmd = new ExitCommand(parent);
         settingsCmd = new SettingsCommand(parent);
        
    	 genSettingsCmd = new GeneralSettingsCommand(parent);
    	 limSettingsCmd = new LimitsSettingsCommand(parent);
    	 gridSettingsCmd = new GridSettingsCommand(parent);
    	 scaSettingsCmd = new ScalesSettingsCommand(parent);

    	 gridCmd = new GridCommand(parent);
         snapCmd = new SnapCommand(parent);
      
         selectAllCmd = new SelectAllCommand(parent);
         deleteCmd = new DeleteCommand(parent);
         zoomCmd = new ZoomCommand(parent);
         zoomInCmd = new ZoomInCommand(parent);
         zoomOutCmd = new ZoomOutCommand(parent);
         fitCmd = new FitCommand(parent);
         zoomAllCmd = new ZoomAllCommand(parent);
         lastZoomCmd = new LastZoomCommand(parent);
         redrawCmd = new RedrawCommand(parent);
    	 undoCmd = new UndoCommand(parent);
         redoCmd = new RedoCommand(parent);
    	
    	 helpTopicsCmd = new HelpTopicsCommand(parent);
         bugReportCmd = new BugReportCommand(parent);
    	 aboutCmd = new AboutCommand(parent);
    	
    }


   
    public void exit(){
        exitCmd.execute();
    }
   
	public void setStateButtons() {
		grid.setSelected(this.getViewState().isGridOn());
		snap.setSelected(this.getViewState().isSnapOn());
	}
    
	public  JFrame getInterface(){
    	return this.parent;
    }
    
    public void setInterface(JFrame par){
    	this.parent = (LearnInterface)par;
    }

    public void setCoord(String x, String y){
    	this.parent.setCoord(x, y);
    }
    
    public void setMessage(String m){
    	this.parent.setMessage(m);
    }


}
